import { DomWarBeaContentPannel } from "./DomWarBeaContentPannel";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { WorldForceRightPart } from "./otherPart/WorldForceRightPart";
import { WorldForceCityCell } from "./WorldForceCityCell";
import { DomWarConst } from "../DomWarConst";
import { SDominionCityInfo } from "../../../../../Message/Public/SDominionCityInfo";
//class WorldForcePannel
    
    export  class WorldForcePannel extends DomWarBeaContentPannel
    {
        constructor(arg1: string="", arg2: Boolean=true, arg3: string="", arg4: number=583, arg5: number=480)
        {
            super(arg1, arg2, arg3, arg4, arg5);
            this._maskW = arg4 - 4;
            this._maskH = arg5 - 4;
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            var loc1=this._mapW - this._bgW + this._mapX;
            var loc2=this._mapH - this._bgH + this._mapY;
            this._dragRect = new Object /* flash.geom.Rectangle */(-loc1, -loc2, loc1, loc2);
            this._mapSprite = new Object /* flash.display.Sprite */();
            this.addChild(this._mapSprite);
            this._mapSprite.x = 0;
            this._mapSprite.y = 0;
            this._mapMask = new Object /* flash.display.Sprite */();
            this._mapMask.graphics.beginFill(0);
            this._mapMask.graphics.drawRect(2, 2, this._maskW, this._maskH);
            this._mapMask.graphics.endFill();
            this.addChild(this._mapMask);
            this._mapMask.x = this._mapSprite.x;
            this._mapMask.y = this._mapSprite.y;
            this._mapMask.alpha = 0.2;
            this._mapSprite.mask = this._mapMask;
            this._mapBmp = new GImageBitmap(ImagesConst.DomWarBeaconMap);
            this._mapSprite.addChild(this._mapBmp);
            this._mapBmp.x = this._mapX;
            this._mapBmp.y = this._mapY;
            this._rightPart = new WorldForceRightPart("", true, "", 205, 480);
            this._rightPart.show(this);
            this._rightPart.x = 590;
            this._mapSprite.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onDownHandler);
            this._mapSprite.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStopDrag);
            this._mapSprite.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onStopDrag);
            this._mapSprite.addEventListener(flash.events.MouseEvent.MOUSE_MOVE, this.onMoveHandler);
            this._cityCtn = new Object /* flash.display.Sprite */();
            this._mapSprite.addChild(this._cityCtn);
            this._cityCtn.x = 374;
            this._cityCtn.y = 261;
            this._cityDict = new Map<any, any> /* flash.utils.Dictionary */();
            this.mainCity = new WorldForceCityCell();
            this.mainCity.isMain = true;
            this._cityCtn.addChild(this.mainCity);
            this.mainCity.x = DomWarConst.MAIN_X;
            this.mainCity.y = DomWarConst.MAIN_Y;
            return;
        }

        public /* override */ update(arg1: Object): void
        {
            this.cityInfo = arg1 as SDominionCityInfo;
            if (this.cityInfo) 
            {
                this._rightPart.update(this.cityInfo);
                this.createCityByMainCity(this.cityInfo.dominionCitys);
            }
            return;
        }

        public createCityByMainCity(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.length;
            var loc5=0;
            while (loc5 < loc1) 
            {
                loc2 = arg1[loc5];
                if (this._cityDict[loc2.x + "_" + loc2.y]) 
                {
                    loc3 = this._cityDict[loc2.x + "_" + loc2.y];
                }
                else 
                {
                    loc3 = new WorldForceCityCell();
                    this._cityDict[loc2.x + "_" + loc2.y] = loc3;
                    loc4 = DomWarConst.getXYByGridPos(loc2.y, loc2.x);
                    loc3.x = loc4.x;
                    loc3.y = loc4.y;
                    this._cityCtn.addChild(loc3);
                }
                loc3.data = loc2;
                ++loc5;
            }
            return;
        }

        /* internal  */createCityCell(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=arg1.length;
            var loc4=75;
            var loc5=102;
            var loc6=0;
            var loc7=0;
            var loc8=0;
            while (loc8 < loc1) 
            {
                loc2 = arg1[loc8];
                if (this._cityDict[loc2.x + "_" + loc2.y]) 
                {
                    loc3 = this._cityDict[loc2.x + "_" + loc2.y];
                }
                else 
                {
                    loc3 = new WorldForceCityCell();
                    if (loc2.x == 4 && loc2.y == 4) 
                    {
                        loc3.isMain = true;
                        loc3.x = 839;
                        loc3.y = 823;
                    }
                    else 
                    {
                        loc3.x = loc2.y * (loc4 + DomWarConst.CITY_W);
                        loc3.y = loc2.x * (loc5 + DomWarConst.CITY_H);
                        if (loc2.x == 4) 
                        {
                            loc3.y = loc3.y + 82;
                        }
                        if (loc2.x >= 5) 
                        {
                            loc3.y = loc3.y + 93;
                        }
                        if (loc2.y == 7) 
                        {
                            loc3.x = loc3.x - 56;
                        }
                        if (loc2.y == 8) 
                        {
                            loc3.x = loc3.x - 132;
                        }
                        if (loc2.x == 4 && loc2.y == 3) 
                        {
                            loc3.x = 591;
                        }
                        this._cityDict[loc2.x + "_" + loc2.y] = loc3;
                        this._cityCtn.addChild(loc3);
                    }
                    loc3.data = loc2;
                }
                ++loc8;
            }
            return;
        }

        protected onMoveHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        protected onStopDrag(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._mapSprite.stopDrag();
            return;
        }

        protected onDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._mapSprite.startDrag(false, this._dragRect);
            return;
        }

        protected /* override */ onImageLoaded(): void
        {
            super.onImageLoaded();
            return;
        }

        public /* override */ destroy(): void
        {
            super.destroy();
            this._mapSprite.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onDownHandler);
            this._mapSprite.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStopDrag);
            this._mapSprite.removeEventListener(flash.events.MouseEvent.MOUSE_MOVE, this.onMoveHandler);
            this._mapSprite.removeEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onStopDrag);
            return;
        }

        /* internal */ /* var */_mapSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_mapBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_mapMask: Object /* flash.display.Sprite */;

        /* internal */ /* var */_maskW: number;

        /* internal */ /* var */_maskH: number;

        /* internal */ /* var */_mapW: number=2400;

        /* internal */ /* var */_mapH: number=2200;

        /* internal */ /* var */_mapX: number=0;

        /* internal */ /* var */_mapY: number=0;

        /* internal */ /* var */_cityCtn: Object /* flash.display.Sprite */;

        /* internal */ /* var */_cityDict: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_dragRect: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */mainCity: WorldForceCityCell;

        /* internal */ /* var */cityInfo: SDominionCityInfo;
    }
